package me.ilvc.kotlinfandroid.ui.activitys

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import me.ilvc.kotlinfandroid.R
import me.ilvc.kotlinfandroid.data.Requestest
import me.ilvc.kotlinfandroid.domain.commands.RequestForcastCommand
import me.ilvc.kotlinfandroid.ui.adapter.ForecastListAdapter
import org.jetbrains.anko.find
import org.jetbrains.anko.longToast
import org.jetbrains.anko.*
import org.jetbrains.anko.uiThread

class MainActivity : AppCompatActivity() {

    private val items = listOf(
            "Mon 6/23 - Sunny - 31/17",
            "Tue 6/24 - Foggy - 21/8",
            "Wed 6/25 - Cloudy - 22/17",
            "Thurs 6/26 - Rainy - 18/11",
            "Fri 6/27 - Foggy - 21/10",
            "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18",
            "Sun 6/29 - Sunny - 20/7")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val forecastList = find<RecyclerView>(R.id.forecast_list)
        forecastList.layoutManager = LinearLayoutManager(this)



        // 执行异步请求
        async {
            val result = RequestForcastCommand("94043").execute()
            uiThread { longToast("Requestest performed") }
            forecastList.adapter = ForecastListAdapter(result)
        }
    }

//    fun  toast(message: String,lenght: Int = Toast.LENGTH_SHORT){
//
//        Toast.makeText(this,message,lenght).show()
//    }



}
